package model;

import java.util.ArrayList;
import java.util.List;

import common.DataManager;
import common.GridCoordinate;
import controller.Controller;

/**
 * @author Colin
 * 
 * The Mine is a defensive item that damages Zombosaurs when 
 * they are on the same tile as the mine.
 *
 */
public class Mine extends DefensiveItem{
	
	private static final int INITIAL_HEALTH = 1;
	private static final int INITIAL_DAMAGE = 5;
	private static final int COST = 50;
	
	private int damage = INITIAL_DAMAGE;
	private boolean destroyed = false;
	private int remainingHealth = INITIAL_HEALTH;	//one health taken away every zombosaur that passes
	private ArrayList<Zombosaur> hurtZombosaurs = new ArrayList<Zombosaur>();
	private ArrayList<GridCoordinate> range = new ArrayList<GridCoordinate>();
	private int rangeInt = 2;	//1 corresponds to 3x3 square, 2 a 4x4 square, etc

	//Mine without position
	public Mine(){
		super("Mine", DataManager.MINE, COST, INITIAL_HEALTH, INITIAL_DAMAGE);
		
	}
	
	//Mine with position
	public Mine(GridCoordinate position){
		super("Mine", DataManager.MINE, COST, position, INITIAL_HEALTH, INITIAL_DAMAGE);
		
	}
	
	private void createRange(){
		ArrayList<GridCoordinate> r = new ArrayList<GridCoordinate>();
		for( int i = -1*this.getRangeInt(); i <= this.getRangeInt(); ++i ){
			for( int j = -1*this.getRangeInt(); j <= this.getRangeInt(); ++j ){
				r.add( new GridCoordinate( getPosition().getX() + i, getPosition().getY() + j));
			}
		}
		this.setRange(r);
	}
	
	/**
	 * The mine is destroyed and zombosaurs damaged
	 */
	public void onContact( Zombosaur zombosaur){
		if(zombosaur instanceof Pzombiedactyl) return;
		createRange();
		destroyed();
	}
	
	private void destroyed(){
		this.destroyed = true;
	}
	
	public boolean isDestroyed(){
		return destroyed;
	}
	
	public int getDamage() {
		return damage;
	}

	public void setDamage(int damage) {
		this.damage = damage;
	}
	
	public int getRangeInt() {
		return rangeInt;
	}

	public void setRangeInt(int rangeInt) {
		this.rangeInt = rangeInt;
	}

	@Override
	public String getDescription() {
		return "The mine explodes on contact, dealing 5 damage to all zombosaurs in the surrounding area."; 
	}

	public void setRange(ArrayList<GridCoordinate> range) {
		this.range = range;
	}

	public ArrayList<GridCoordinate> getRange() {
		return range;
	}
}
